<%@ page contentType="text/html;charset=utf-8" language="java" %>
<%@ include file="/WEB-INF/views/jsp/common/taglibs.jsp" %>
<head>
    <title>${platform_title}-会员列表</title>
    <%@ include file="/WEB-INF/views/jsp/common/meta.jsp" %>
    <%@ include file="/WEB-INF/views/jsp/common/link.jsp" %>
</head>
<body>
<form class="form-inline definewidth m20" action="${ctx}/security/user/list" method="post">
    <table class="table">
        <tr>
            <td>登录名:</td>
            <td><input type="text" name="loginName" value="${loginName}"><span class="emphasize">(支持模糊查询)</span></td>
            <td>昵称:</td>
            <td><input type="text" name="nickName" value="${nickName}"><span class="emphasize">(支持模糊查询)</span></td>
            <td>
                <button type="submit" class="btn btn-primary">查询</button>
            </td>
        </tr>
    </table>
</form>
<table class="table table-bordered table-hover definewidth m10">
    <thead>
    <tr>
        <th><em>登录名</em></th>
        <th><em>昵称</em></th>
        <th><em>状态</em></th>
        <th><em>创建日期</em></th>
        <th><em>最后更新日期</em></th>
        <c:if test="${currentUser.securityUser.opRole.code eq 'super'}">
            <th><em>操作</em></th>
        </c:if>
    </tr>
    </thead>
    <tbody>
    <c:if test="${not empty rows}">
        <c:forEach items="${rows}" var="entity">
            <tr>
                <td><span>${entity.operateUserId}</span></td>
                <td><span>${entity.screenName}</span></td>
                <td>
                    <span id="status_user_code_${entity.operateUserId}" <c:if test="${entity.validateStatus ne validStatus}">  class="emphasize" </c:if>>
                        <fmt:message key="def.security.user.valid.status.code.${entity.validateStatus.code}.name" bundle="${def}"/>
                    </span>
                </td>
                <td><span><fmt:formatDate value="${entity.createDate}" pattern="yyyy-MM-dd HH:mm:ss"/></span></td>
                <td><span><fmt:formatDate value="${entity.updateDate}" pattern="yyyy-MM-dd HH:mm:ss"/></span></td>
                <c:if test="${currentUser.securityUser.opRole.code eq 'super'}">
                    <td>
                        <c:if test="${entity.opRole.code ne 'super'}">
                            <a class='btn  <c:choose>
                                <c:when test="${entity.validateStatus eq validStatus}">
                                    btn-danger
                                </c:when>
                                <c:otherwise>
                                    btn-info
                                </c:otherwise>
                            </c:choose>'
                               onclick="operateAccount(this,'${ctx}','${entity.operateUserId}');"
                               href="javascript:void(0);">
                                <c:choose>
                                    <c:when test="${entity.validateStatus eq validStatus}">
                                        <c:out value="锁定"/>
                                    </c:when>
                                    <c:otherwise>
                                        <c:out value="激活"/>
                                    </c:otherwise>
                                </c:choose>
                            </a>
                        </c:if>
                    </td>
                </c:if>
            </tr>
        </c:forEach>
    </c:if>
    </tbody>
</table>
<div class="inline pull-right page">
    <c:if test="${page.maxPage > 1}">
        <pg:pager url="${ctx}/account/list"
                  items="${page.totalRows}" isOffset="true"
                  maxPageItems="${page.pageSize}"
                  export="offset, currentPageNumber=pageNumber" scope="request">
            <pg:param name="maxPageItems" value="${page.pageSize}"/><!--不能缺少的-->
            <pg:param name="items" value="${page.totalRows}"/>
            <pg:param name="loginName" value="${loginName}"/>
            <pg:param name="nickName" value="${nickName}"/>
            <%@ include file="/WEB-INF/views/jsp/common/page.jsp" %>
        </pg:pager>
    </c:if>
</div>
</body>
<script type="text/javascript">
    function operateAccount(obj,contextPath, loginId) {
        $.post(contextPath + "/security/user/operate", {securityUserId: loginId}, function (result) {
            var data = eval(result);
            if (data.statusCode == '1') {
                if (data.msg == 'locked') {
                    //按钮变成锁定
                    $(obj).removeClass("btn-info").addClass("btn-danger").html("锁定");
                    $("#status_user_code_" + loginId).removeClass("emphasize").html("激活")
                } else {
                    //按钮变成激活
                    $(obj).removeClass("btn-danger").addClass("btn-info").html("激活");
                    $("#status_user_code_" + loginId).addClass("emphasize").html("锁定")
                }
            } else {
                BUI.Message.Alert(data.msg, 'error');
            }
        });
    }
</script>
</html>